/*
 * @Descripttion: 
 * @version: 
 * @Author: wtzhang
 * @Date: 2021-07-28 14:53:42
 * @LastEditors: wtzhang
 * @LastEditTime: 2021-07-29 10:38:09
 */
import Vue from 'vue'
import Vuex from "vuex"

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 0
  },
  mutations: {
    add(state) {
      // 变更状态
      state.count++
    },
    addN(state, step) {
      // 变更状态
      state.count += step
    },
    subtract(state) {
      // 变更状态
      state.count --
    },
    subtractN(state, step) {
      // 变更状态
      state.count -= step
    }
  },
  actions: {
    addAsync(context) {
      setTimeout(() => {
        context.commit('add')
      }, 1000);
    },
    addAsync2(context, step) {
      setTimeout(() => {
        context.commit('addN', step)
      }, 1000);
    }
  },
  getters: {
    showNum(state) {
      return '当前最新的数量是【'+ state.count +'】'
    }
  },
  modules: {
  }
})

export default store
